package com.meisiabc.utils;

public final class Verify {
    private Verify() {
    }

    public static void isTrue(boolean expression) {
        if (!expression) {
            throw new VerifyException();
        }
    }

    public static void isTrue(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {
        if (!expression) {
            throw new VerifyException(format(errorMessageTemplate, errorMessageArgs));
        }
    }

    public static <T> T notNull(T reference) {
        return notNull(reference, "expected a non-null reference");
    }

    public static <T> T notNull(T reference, String errorMessageTemplate, Object... errorMessageArgs) {
        isTrue(reference != null, errorMessageTemplate, errorMessageArgs);
        return reference;
    }

    private static String format(String template, Object... args) {
        return StringFormat.format(template, args);
    }
}
